package com.unitd.frame.springweb.upload.multipart.policy.impl;

import com.unitd.frame.comm.utils.Base58;
import com.unitd.frame.springweb.upload.multipart.policy.IFileRenamePolicy;

import java.io.File;

/**
 * @desc 上传文件重命名策略类
 * @filename UploadFileRenamePolicy.java
 * @copyright www.unitd.com
 * @author Hudan
 * @version 1.0
 * @date 2017/4/10
 */
public class UploadFileRenamePolicy implements IFileRenamePolicy {
	/** 上传文件的后缀 */
	private String suffix;

	public UploadFileRenamePolicy() {
	}

	/**
	 * @desc 对上传的文件进行重命名操作处理
	 * @param file 需要重命名的文件
	 * @return 重命名后的文件对象
	 */
	@Override
	public File rename(File file) {
		StringBuffer pathName = new StringBuffer();
		// 采用Base58获取UUID
		pathName.append(Base58.compressedUUID());
		pathName.append(this.getSuffix());
		file = new File(file.getParent(), pathName.toString());
		return file;
	}

	public String getSuffix() {
		return this.suffix;
	}

	public void setSuffix(String suffix) {
		this.suffix = suffix;
	}
}